﻿using System;
using System.IO;

namespace Eater
{
    class ResultFile : IDisposable
    {
        FileStream file;
        StreamWriter writer;

        public ResultFile(string filename)
        {
            file = new FileStream(filename, FileMode.Create);
            writer = new StreamWriter(file);
        }

        public void WriteResult(long n, long timeMS)
        {
            writer.WriteLine("{0}, {1}", n.ToString(), timeMS.ToString());
            writer.Flush();
        }

        public void WriteResult(string attribute, string value)
        {
            writer.WriteLine("{0}, {1}", attribute, value);
            writer.Flush();
        }

        public void WriteResult(params object[] p)
        {
            int n = p.Length;
            int i;
            for (i = 0; i < n - 1; i++)
            {
                writer.Write(p[i]);
                writer.Write(", ");
            }
            writer.WriteLine(p[i]);
            writer.Flush();
        }

        public void WriteResult(double[] p)
        {
            int n = p.Length;
            int i;
            for (i = 0; i < n - 1; i++)
            {
                writer.Write("{0:0.00000}; ", p[i]);
            }
            writer.WriteLine("{0:0.00000}", p[i]);
            writer.Flush();
        }

        public void Dispose()
        {
            writer.Dispose();
            file.Dispose();
        }
    }
}
